package org.social.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import org.social.db.cache.FriendCache;
import static org.social.db.StaticResource.FriendResource.*;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.social.db.StaticResource.FriendResource.*;
/**
 * 好友关系
 */
public class Friend extends BasePojo<Friend> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[5];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* 玩家ID
	* 1:好友
	* 2:黑名单
	* 3:好友申请
	*/
	private int playerId;
	
	/**
	* 好友ID
	*/
	private int friendId;
	
	/**
	* 状态
	*/
	private int status;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 是否有礼品
	*/
	private boolean gift;
	
	/**
	* 最后送礼时间
	*/
	private java.util.Date lastGiveDate;
	
	
	@Deprecated
	public static Friend builder() {
		Friend friend = new Friend();
		return friend;
	}
	
	@Deprecated
	public Friend() {
		super();
	}
	
	public Friend(int id, int playerId, int friendId, int status, boolean gift, java.util.Date lastGiveDate) {
		super();
		this.id = id;
		this.playerId = playerId;
		this.friendId = friendId;
		this.status = status;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.gift = gift;
		this.lastGiveDate = lastGiveDate;
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public Friend setId(int id) {this.id = id;return this;}
	
	/**
	 * 玩家ID
	 * 1:好友
	 * 2:黑名单
	 * 3:好友申请
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家ID
	 * 1:好友
	 * 2:黑名单
	 * 3:好友申请
	 */
	public Friend setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 好友ID
	 */
	public int getFriendId() {return friendId;}
	
	/**
	 * 好友ID
	 */
	public Friend setFriendId(int friendId) {this.friendId = friendId;return this;}
	
	/**
	 * 状态
	 */
	public int getStatus() {return status;}
	
	/**
	 * 状态
	 */
	public Friend setStatus(int status) {this.status = status;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Friend setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Friend setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 是否有礼品
	 */
	public boolean isGift() {return gift;}
	
	/**
	 * 是否有礼品
	 */
	public Friend setGift(boolean gift) {this.gift = gift;return this;}
	
	/**
	 * 最后送礼时间
	 */
	public java.util.Date getLastGiveDate() {return lastGiveDate;}
	
	/**
	 * 最后送礼时间
	 */
	public Friend setLastGiveDate(java.util.Date lastGiveDate) {this.lastGiveDate = lastGiveDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.playerId;
        values[2] = this.friendId;
        values[3] = this.status;
        values[4] = this.createDate;
        values[5] = this.modifiedDate;
        values[6] = this.gift;
        values[7] = this.lastGiveDate;
        return values;
	}
	
	public Friend deepCopy(){
		Friend friend = null;
		try {
			friend = (Friend) super.clone();
		    friend.setCreateDate(ToolCopy.copyObject(this.createDate));
		    friend.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    friend.setLastGiveDate(ToolCopy.copyObject(this.lastGiveDate));
		    // 克隆索引
		    friend.indexValues = ArrayUtils.clone(indexValues);
			return friend;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return friend;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.playerId);
        map.put(keys[2], this.friendId);
        map.put(keys[3], this.status);
        map.put(keys[4], this.createDate);
        map.put(keys[5], this.modifiedDate);
        map.put(keys[6], this.gift);
        map.put(keys[7], this.lastGiveDate);
        return map;
    }
    
    protected Friend createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.playerId = (int)map.get(keys[1]);
   		this.friendId = (int)map.get(keys[2]);
   		this.status = (int)map.get(keys[3]);
   		this.createDate = (java.util.Date)map.get(keys[4]);
   		this.modifiedDate = (java.util.Date)map.get(keys[5]);
   		this.gift = (boolean)map.get(keys[6]);
   		this.lastGiveDate = (java.util.Date)map.get(keys[7]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.playerId);
        obj.put(keys[2], this.friendId);
        obj.put(keys[3], this.status);
        obj.put(keys[4], this.createDate);
        obj.put(keys[5], this.modifiedDate);
        obj.put(keys[6], this.gift);
        obj.put(keys[7], this.lastGiveDate);
        return obj;
    }
    
    protected Friend createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.playerId = obj.getIntValue(keys[1]);
	    this.friendId = obj.getIntValue(keys[2]);
	    this.status = obj.getIntValue(keys[3]);
	    this.createDate = obj.getDate(keys[4]);
	    this.modifiedDate = obj.getDate(keys[5]);
	    this.gift = obj.getBooleanValue(keys[6]);
	    this.lastGiveDate = obj.getDate(keys[7]);
        return this;
    }
    
    
    public Friend createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.friendId = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.status = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[4]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.gift = rs.getBoolean(SOURCE_COLUMN_NAMES[6]);
	    this.lastGiveDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[7]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeInt(this.friendId);
	    byteBuf.writeInt(this.status);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeBoolean(this.gift);
	    byteBuf.writeDate(this.lastGiveDate);
    }
	
	protected Friend readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.playerId = byteBuf.readInt(null);
	    this.friendId = byteBuf.readInt(null);
	    this.status = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.gift = byteBuf.readBoolean(null);
	    this.lastGiveDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Friend insert(){
    	return FriendCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Friend update(){
    	return FriendCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return FriendCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Friend insertAndFlush(){
    	return FriendCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Friend updateAndFlush(){
    	return FriendCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return FriendCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Friend syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId(),"_",getFriendId(),"_",getStatus()).e();
		indexValues[2] = SK_Plus.b(getPlayerId(),"_",getFriendId()).e();
		indexValues[3] = SK_Plus.b(getPlayerId()).e();
		indexValues[4] = SK_Plus.b(getPlayerId(),"_",getStatus()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}